package com.stars.empoly.adapter

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.R
import com.stars.empoly.databinding.ItemEnterinfoBinding
import com.stars.empoly.model.DataInfoBean
import com.yanzhenjie.permission.Action
import com.yanzhenjie.permission.AndPermission
import com.trailer.base.base.BAdapter

class OrderInfoInadapter() : BAdapter<DataInfoBean.OrderBean.ReceiveBean, BaseDataBindingHolder<ItemEnterinfoBinding>>(R.layout.item_enterinfo) {

    @SuppressLint("WrongConstant")
    override fun convert(holder: BaseDataBindingHolder<ItemEnterinfoBinding>, item: DataInfoBean.OrderBean.ReceiveBean) {
        holder.dataBinding?.position=holder.adapterPosition
        holder.dataBinding?.item = item


        holder.dataBinding?.tvPhone!!.onClick {

            //拨打电话
            if (TextUtils.isEmpty(item.mobile)) {
                toast("未添加电话！！")
                return@onClick
            }
            AndPermission.with(context)
                    .runtime()
                    .permission(Manifest.permission.CALL_PHONE)
                    .onGranted(Action<List<String?>?> {
                        val intent = Intent(Intent.ACTION_DIAL)
                        val uri = Uri.parse("tel:$item.mobile")
                        intent.data = uri
                        context!!.startActivity(intent)
                    }).start()

        }

    }

}
